package com.ruoyi.web.controller.finance;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.finance.domain.PaymentWaterFormUpload;
import com.ruoyi.finance.domain.vo.PaymentMasterVo;
import com.ruoyi.finance.domain.vo.PaymentVoucherLogVo;
import com.ruoyi.finance.service.IPaymentVoucherService;
import com.ruoyi.procured.domain.ProcuredPlan;
import com.ruoyi.procured.domain.vo.PaymentReturnFormUpload;
import com.ruoyi.procured.domain.vo.PaymentReturnVO;
import com.ruoyi.procured.service.IPaymentReturnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.ruoyi.common.utils.PageUtils.startPage;

/**
 * 付款单Controller
 *
 */
@RestController
@RequestMapping("/finance/paymentReturn")
public class PaymentReturnController extends BaseController
{
    @Autowired
    private IPaymentReturnService paymentReturnService;

    /**
     * 查询退款单列表
     */
    @PreAuthorize("@ss.hasPermi('finance:paymentReturn:list')")
    @GetMapping("/selectPaymentReturnList")
    public TableDataInfo list(PaymentReturnVO paymentReturnVO)
    {
        startPage();
        List<PaymentReturnVO> list = paymentReturnService.selectPaymentReturnVoList(paymentReturnVO);
        return getDataTable(list);
    }
    /**
     * 上传退款单
     */
    @PreAuthorize("@ss.hasPermi('finance:paymentReturn:posting')")
    @PostMapping("/uploadReturnImage")
    public AjaxResult edit(@RequestBody PaymentReturnFormUpload formUpload)
    {
        return toAjax(paymentReturnService.uploadReturnImage(formUpload,getNickname()));
    }

    /**
     * 标记退款单已收款
     */
    @PreAuthorize("@ss.hasPermi('finance:paymentReturn:mark')")
    @PostMapping("/setPaymentRequestMark/{paymentRequestId}")
    public ResponseEntity<String> edit(@PathVariable String paymentRequestId)
    {
        if(paymentRequestId.isEmpty()){
            throw new ServiceException("获取申请款ID失败");
        }
        paymentReturnService.setPaymentRequestMark(paymentRequestId, getNickname());
        return  ResponseEntity.ok("状态更新成功");
    }
}
